package FileIO.ReaderWriter;

import FileIO.Student;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;

public class usePrintWriter {
    public static void main(String[] args) throws FileNotFoundException {
        List<Student> studentList = Arrays.asList(new Student[] {
                new Student("王二", 18, 80.9d),
                new Student("王小波", 20, 67.5d)
        });
        writeStudents(studentList);
    }

    public static void writeStudents(List<Student> students) throws FileNotFoundException {
        PrintWriter writer = new PrintWriter("src/main/data/students.txt");
        try {
            for (Student s : students) {
                writer.println(s.getName() + "," + s.getAge() + "," + s.getScore());
            }
        } finally {
            writer.close();
        }
    }
}
